﻿<template>
  <a-modal
    :title="title"
    width="50%"
    :visible="visible"
    :confirmLoading="loading"
    @ok="handleSubmit"
    @cancel="()=>{this.visible=false}"
  >
    <a-spin :spinning="loading">
      <a-form-model ref="form" :model="entity" :rules="rules" v-bind="layout">
        <a-form-model-item label="类型编码" prop="typenum">
          <a-input v-model="entity.typenum" autocomplete="off" />
        </a-form-model-item>
        <a-form-model-item label="类型名称" prop="name">
          <a-input v-model="entity.name" autocomplete="off" />
        </a-form-model-item>
        <a-form-model-item label="排序" prop="sort">
          <a-input v-model="entity.sort" type="Number" autocomplete="off" />
        </a-form-model-item>
        
        <a-form-model-item label="是否显示" prop="isShow">
          <a-radio-group default-value="1" button-style="solid" v-model="entity.isShow">
        <a-radio-button :value="1">
          是
        </a-radio-button>
        <a-radio-button :value="0">
          否
        </a-radio-button>
      </a-radio-group>
        </a-form-model-item>
        <a-form-model-item label="说明" prop="remark">
          <a-input v-model="entity.remark" :rows="3" type="textarea" autocomplete="off" />
        </a-form-model-item>
        <!-- <a-form-model-item label="数据权限" prop="DataAreaId">
          <a-input v-model="entity.DataAreaId" autocomplete="off" />
        </a-form-model-item> -->
      </a-form-model>
    </a-spin>
  </a-modal>
</template>

<script>
export default {
  props: {
    parentObj: Object
  },
  data() {
    return {
      layout: {
        labelCol: { span: 5 },
        wrapperCol: { span: 18 }
      },
      visible: false,
      loading: false,
      entity: {},
      rules: {
        typenum:[{ required: true, message: '请输入类型编码' }],
        name:[{ required: true, message: '请输入类型名称' }],
      },
      title: ''
    }
  },
  methods: {
    init() {
      this.title = "新增"
      this.visible = true
      this.entity = {}
      this.$nextTick(() => {
        this.$refs['form'].clearValidate()
      })
    },
    openForm(id, title) {
      this.init()

      if (id) {
        this.title = "修改"
        this.loading = true
        this.$http.post('/Base_leasesystem_dictionary_types/leasesystem_dictionary_types/GetTheData', { id: id }).then(resJson => {
          this.loading = false

          this.entity = resJson.Data
        })
      }
    },
    handleSubmit() {
      this.$refs['form'].validate(valid => {
        if (!valid) {
          return
        }
        this.loading = true
        this.$http.post('/Base_leasesystem_dictionary_types/leasesystem_dictionary_types/SaveData', this.entity).then(resJson => {
          this.loading = false

          if (resJson.Success) {
            this.$message.success('操作成功!')
            this.visible = false

            this.parentObj.getDataList()
          } else {
            this.$message.error(resJson.Msg)
          }
        })
      })
    }
  }
}
</script>
